<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        
/*
	阿拉伯数字转中文数字
	参数：
		str:阿拉伯数字   num || str
*/
function toChineseNum(str) {
	str = ('' + str).trim().replace(/^0*/, ''); //去掉前面修饰的0
	var match = ['', '一', '二', '三', '四', '五', '六', '七', '八', '九', '零'];
	return ('0000' + str).substr((str.length % 4) || 4).replace(/(\d){4}/g, function (_str, endIndex, startIndex) {
		var dot = (((str.length - 1) / 4) >> 0) - ((startIndex / 4) >> 0);
		var prefix = (function getPrfix(dot) {
			return (dot > 2 ? (+_str ? (dot == 3 ? '万' : (getPrfix(dot - 1) + '万')) : '') : (dot == 1 ? (+_str ? '万' : '') : (dot == 2 ? '亿' : '')));
		})(dot);
		/0+$/g.test(_str) && (prefix += match[10]); //处理单元内后半部分有零的地方
		return (+_str) ? (_str.replace(/(\d)(\d)(\d)(\d)/g, function ($0, $1, $2, $3, $4) {
			!match[$1] && (match[$2] ? ($1 = 10) : (match[$3] ? ($2 = 10) : (match[$4] ? ($3 = 10) : ''))); //处理相邻单元前半部分
			match[$1] && match[$3] && !match[$2] && ($2 = 10), match[$2] && match[$4] && !match[$3] && ($3 = 10), match[$1] && match[$4] && !match[$3] && !match[$2] && ($3 = 10); //中间两个连续为0，只是获取最后一个
			return (match[$1] && ($1 < 10 ? (match[$1] + '千') : match[$1])) + (match[$2] && ($2 < 10 ? (match[$2] + '百') : match[$2])) + (match[$3] && ($3 < 10 ? ($3 == 1 ? '十' : (match[$3] + '十')) : match[$3])) + (match[$4] && match[$4]);
		}) + prefix) : (prefix);
	}).replace(/^零*/g, '').replace(/零*$/g, '').replace(/(零)*/g, '$1').replace(/零亿/g, '亿') || match[10]; //处理连续零的问题
}
    </script>
</body>

</html>